//
//  LOLNewsViewController.m
//  LOLNews
//
//  Created by MXL on 16/10/28.
//  Copyright © 2016年 KK. All rights reserved.
//

#import "LOLNewsViewController.h"
#import "HMSlideView.h"
#import "LOLSlideImageModel.h"
#import "YYModel.h"
#import "AFNetworking.h"
#import "LOLSlideImageModel.h"
#import "LOLCategoryView.h"
#import "SDCycleScrollView.h"

@interface LOLNewsViewController () <SDCycleScrollViewDelegate>

/**
 *  轮播器图片数组
 */
@property(nonatomic,strong) NSArray *slideImageList;
/**
 *  轮播器
 */
@property (nonatomic,weak) SDCycleScrollView *slideView;


@end


@implementation LOLNewsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - 导航栏变为透明
- (void)viewDidAppear:(BOOL)animated {
    
    
    self.navigationController.navigationBar.alpha = 0;
    
    //设置导航栏样式
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 加载图片轮播器数据
- (void)loadData {
    
    //创建网络请求管理者
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    //发送 GET，请求网络 JSON 数据
    [manager GET:@"http://qt.qq.com/static/pages/news/phone/c13_list_1.shtml?plat=android&version=9711" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        //JSON转模型
        NSArray *slideImageList = [NSArray yy_modelArrayWithClass:[LOLSlideImageModel class] json:responseObject];
        
        NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:slideImageList.count];
        
        for (LOLSlideImageModel *model in slideImageList) {
            
            [arrM addObject:model.image_url_big];
        }
        
        //刷新数据
        self.slideView.imageURLStringsGroup = arrM.copy;
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];


}

#pragma mark - 界面
- (void)setupUI{
    
    [self loadData];
    
    self.view.backgroundColor = [UIColor clearColor];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    //图片轮播器 View
    SDCycleScrollView *slideView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 180) delegate:self placeholderImage:[UIImage imageNamed:@"1"]];
    
    [self.view addSubview:slideView];
    
    //记录属性
    self.slideView = slideView;
    
    //分类按钮视图
    LOLCategoryView *categoryView = [[LOLCategoryView alloc] init];
    
    [self.view addSubview:categoryView];
    
    //自动布局
    [categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.left.equalTo(self.view);
        make.top.equalTo(slideView.mas_bottom);
        make.height.mas_equalTo(45);
    }];
    
    //资讯滚动视图
    UIScrollView *newsScrollView = [[UIScrollView alloc] init];
    
    newsScrollView.backgroundColor = [UIColor blueColor];
    
    [self.view addSubview:newsScrollView];
    
    //自动布局
    [newsScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(categoryView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
}

#pragma mark - 懒加载轮播图片数组
- (NSArray *)slideImageList {
    
    if (_slideImageList == nil) {
        
        _slideImageList = [NSArray array];
        
        return _slideImageList;
    }
    
    return _slideImageList;
}

@end
